package edu.guigu.databindingdemo;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import edu.guigu.databindingdemo.databinding.ActivityDataBindingDemoBinding;

// ViewBinding
// DataBinding
public class DataBindingDemoActivity extends AppCompatActivity {

    private ActivityDataBindingDemoBinding dataBinding;
    private User user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_data_binding_demo);
        user = new User("张三", 20);
        dataBinding.setUser(user);

//        dataBinding.button.setOnClickListener(v -> {
//            user.setAge((int)(Math.random()*100));
//            user.setName("李四"+Math.random());
//        });
        dataBinding.setClick(new OnButtonClickListener());
    }

    public class OnButtonClickListener{
        public void onClick(View view) {
            user.setAge((int)(Math.random()*100));
            user.setName("李四"+Math.random());
        }
    }
}